home *** CD-ROM | disk | FTP | other *** search
/ PC-X 1997 October / pcx14_9710.iso / swag / delphi.swg / 0032_Copy files usings LZExpand.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1995-11-22  |  1.5 KB  |  43 lines

  1.  
  2. For an installation program, I needed to be able to copy files into certain
  3. directories.  After having come up with a file-copy solution much like Mr.
  4. Stidolph's, I found myself needing a way to copy a file of any size, without
  5. having to blow the stack on a large file buffer.
  6.  
  7. To this end, I explored the LZExpand unit and developed the function shown
  8. below.  Note that this function expects to find the source file as a
  9. standard DOS LZ-compressed file.  (These are the files you find on DOS and
  10. Windows installation disks that look like "SETUP.EX_".)  You need to use the
  11. DOS utility COMPRESS to first convert the source file to a COMPRESSed file.
  12. Unfortunately, Delphi does not come with COMPRESS!  (Why not, Borland?)
  13. You'll need to grab it from another compiler package (like BP or BC++.)
  14.  
  15. { CopyFile returns True on a successful copy, False on failure. }
  16. function CopyFile( src, dest: String): Boolean;
  17.    var
  18.       s, d: TOFStruct;
  19.       fs, fd: Integer;
  20.       fnSrc, fnDest: PChar;
  21.    begin
  22.       src:=src + #0;
  23.       dest:=dest + #0;
  24.       fnSrc:=@src[1];   { Trick the Strings into being ASCIIZ }
  25.       fnDest:=@dest[1];
  26.  
  27.       fs := LZOpenFile( fnSrc, s, OF_READ );    { Get file handles }
  28.       fd := LZOpenFile( fnDest, d, OF_CREATE );
  29.  
  30.       if LZCopy( fs, fd ) < 0 then      { Here's the magic API call }
  31.          Result:=False
  32.       else
  33.          Result:=True;
  34.  
  35.       LZClose( fs );    { Make sure to close 'em! }
  36.       LZClose( fd );
  37.    end;
  38.  
  39.  
  40. -JSRS
  41.  
  42.  
  43.